<?php use_helper('I18N'); ?>
<style type="text/css">
    p img {
        background: none repeat scroll 0 0 white;
        border: 1px solid #BBBBBB;
        margin: 7px 14px 7px 0;
        padding: 5px;
        height: 50px;
        /*width: 160px;*/
    }
</style>

<script type="text/javascript">
$(function() {
    $("#btnUpdate").button({
            icons: {
                primary: "ui-icon-circle-plus"
            }
        }).click(function(){
        });

    $("#btnBack").button({
        icons: {
            primary: "ui-icon-circle-arrow-w"
        }
    });
});
</script>
<div id="content">

    <!-- ========== CATEGORIES TABS ========= -->
    <!-- ==================================== -->
    <table id="contentMainWrapper" border="0" cellpadding="0" cellspacing="0" width="100%">
        <tbody>
        <tr>
            <td id="column-left" style="width: 215px;">
                <div style="width:215px;">
                    <!--// bof: categories //-->
                    <div class="box" id="categories" style="width:215px;">
                        <div class="box-border">
                            <div class="box-head">
                                <?php echo __('Categories') ?>
                            </div>
                            <div class="box-body">
                                <?php include_component('component', 'categoriesSideMenu') ?>
                            </div>
                        </div>
                    </div>
                    <!--// eof: categories //-->
                    <!--// bof: specials //-->
                    <div class="box" id="specials" style="width:215px;">
                        <div class="box-border">
                            <div class="box-head">
                                <a href="<?php echo url_for("/product/specialItem") ?>"><?php echo __('Specials') ?></a>
                            </div>
                            <div class="box-body">
                                <?php include_component('component', 'specialsSideMenu', array('param' => 'will implement for categoryType')) ?>
                            </div>

                        </div>
                    </div>
                    <!--// eof: specials //-->
                </div>
            </td>
            <td id="column-center" valign="top">
                <!-- BOF- BANNER #3 display -->
                <!-- EOF- BANNER #3 display -->
                <div class="column-center-padding">
                    <!--content_center-->
                    <!-- bof breadcrumb -->
                    <!-- eof breadcrumb -->
                    <!-- bof upload alerts -->
                    <!-- eof upload alerts -->
                    <div class="centerColumn" id="addressBookDefault">
                        <?php if ($sf_flash->has('errorMsg')): ?>
                            <?php echo $sf_flash->get('errorMsg') ?>
                        <?php endif; ?>
                        <h1 id="addressBookDefaultHeading">My Personal Address Book</h1>

                        <h2 id="addressBookDefaultPrimary">Primary Address</h2>

                        <div class="buttonRow forward">

                            <a href="<?php echo url_for("/member/editAddressBook?id=".$primaryAddress->getAddressId()); ?>" style="text-decoration: none">
                            <img src="/images/buttons/arrow-right.png"
                                 alt="<?php echo __('Edit') ?>"
                                 title="<?php echo __('Edit') ?>">&nbsp;<strong><?php echo __('Edit') ?></strong></a>
                        </div>
                        <address>
                            <?php $address = $primaryAddress->getAddress1();

                            if ($primaryAddress->getAddress2() != null && $primaryAddress->getAddress2() != "")
                                $address .= "<br>" . $primaryAddress->getAddress2();

                            $address2 = "";
                            if ($primaryAddress->getPostcode() != null && $primaryAddress->getPostcode() != "")
                                $address2 = $primaryAddress->getPostcode();

                            if ($primaryAddress->getCity() != null && $primaryAddress->getCity() != "") {
                                if ($address2 != "")
                                    $address2 .= " ";
                                $address2 .= $primaryAddress->getCity();
                            }
                            if ($primaryAddress->getState() != null && $primaryAddress->getState() != "") {
                                if ($address2 != "")
                                    $address2 .= "<br>";
                                $address2 .= $primaryAddress->getState();
                            }
                            if ($primaryAddress->getCountry() != null && $primaryAddress->getCountry() != "") {
                                if ($address2 != "")
                                    $address2 .= " ";
                                $address2 .= $primaryAddress->getCountry();
                            }

                            echo $address."<br>".$address2;
                            ?>
                        </address>

                        <br class="clearBoth">

                        <div class="instructions">
                            This address is used as the pre-selected shipping and billing address for orders placed on this store.
                            <br>
                            This address is also used as the base for product and service tax calculations.
                        </div>
                        <hr>
                        <br class="clearBoth">
                        <?php if (count($nonPrimaryAddresses) > 0) { ?>
                        <fieldset>
                            <legend>Address Book Entries</legend>
                            <div class="alert forward"><span class="coming"><strong>NOTE:</strong></span> A maximum of 5
                                address book entries allowed.
                            </div>
                            <br class="clearBoth">

                            <?php
                            foreach ($nonPrimaryAddresses as $nonPrimaryAddress):
                            ?>
                            <h3 class="addressBookDefaultName">&nbsp;&nbsp; <?php echo $nonPrimaryAddress->getAddress1(); ?></h3>

                            <address>
                                <?php $address = $nonPrimaryAddress->getAddress1();

                                if ($nonPrimaryAddress->getAddress2() != null && $nonPrimaryAddress->getAddress2() != "")
                                    $address .= "<br>" . $nonPrimaryAddress->getAddress2();

                                $address2 = "";
                                if ($nonPrimaryAddress->getPostcode() != null && $nonPrimaryAddress->getPostcode() != "")
                                    $address2 = $nonPrimaryAddress->getPostcode();

                                if ($nonPrimaryAddress->getCity() != null && $nonPrimaryAddress->getCity() != "") {
                                    if ($address2 != "")
                                        $address2 .= " ";
                                    $address2 .= $nonPrimaryAddress->getCity();
                                }
                                if ($nonPrimaryAddress->getState() != null && $nonPrimaryAddress->getState() != "") {
                                    if ($address2 != "")
                                        $address2 .= "<br>";
                                    $address2 .= $nonPrimaryAddress->getState();
                                }
                                if ($nonPrimaryAddress->getCountry() != null && $nonPrimaryAddress->getCountry() != "") {
                                    if ($address2 != "")
                                        $address2 .= " ";
                                    $address2 .= $nonPrimaryAddress->getCountry();
                                }

                                echo $address."<br>".$address2;
                                ?>
                            </address>

                            <div class="buttonRow forward">
                                <a href="<?php echo url_for("/member/setAsPrimary?id=".$nonPrimaryAddress->getAddressId()); ?>" style="text-decoration: none">
                                <img src="/images/buttons/arrow-right.png"
                                     alt="<?php echo __('Set as primary') ?>"
                                     title="<?php echo __('Set as primary') ?>">&nbsp;<strong><?php echo __('Set as primary') ?></strong></a>

                                <a href="<?php echo url_for("/member/editAddressBook?id=".$nonPrimaryAddress->getAddressId()); ?>" style="text-decoration: none">
                                <img src="/images/buttons/arrow-right.png"
                                     alt="<?php echo __('Edit') ?>"
                                     title="<?php echo __('Edit') ?>">&nbsp;<strong><?php echo __('Edit') ?></strong></a>

                                <a href="<?php echo url_for("/member/deleteAddressBook?id=".$nonPrimaryAddress->getAddressId()); ?>" style="text-decoration: none">
                                <img src="/images/buttons/arrow-right.png"
                                     alt="<?php echo __('Delete') ?>"
                                     title="<?php echo __('Delete') ?>">&nbsp;<strong><?php echo __('Delete') ?></strong></a>
                            </div>

                            <br class="clearBoth">
                            <hr>
                            <?php endforeach; ?>
                        </fieldset>
                        <?php } ?>
                        <?php if (count($nonPrimaryAddresses) < 4) { ?>
                        <div class="buttonRow forward">
                            <a id="btnUpdate"
                               href="<?php echo url_for("/member/addAddressBook");?>"><?php echo __('Add New Address') ?></a>
                        </div>
                        <?php } ?>
                        <div class="buttonRow back">
                            <a id="btnBack"
                               href="<?php echo url_for("/member/myAccount");?>"><?php echo __('Back') ?></a>
                        </div>

                        <br class="clearBoth">
                    </div>

                    <div class="clear"></div>
                    <!--eof content_center-->
                </div>
                <!-- BOF- BANNER #4 display -->
                <!-- EOF- BANNER #4 display -->
            </td>
        </tr>
        </tbody>
    </table>
</div>